<style>
</style>
<template>
  <list_url ref="list_url" :config="config">
    <template #action="{row}">
      <el-button @click="to_edit(row)" size="small">详情</el-button>
    </template>
  </list_url>

  <el-dialog v-model="parent_list.show" width="850px" type="0">
    <list :cols="parent_list.list_cols" :data="parent_list.list"></list>
  </el-dialog>
</template>
<script>
import {_config} from "@/js/s94_tool.js";
import {iframe, in_right_admin} from "@/js/tool.js";
import s94Mjs from "s94-js";
import {ajax} from "@/js/api_tool.js";

export default {
  props: ['__iframe'],
  data(){
    let app = this, btns = {}, is_del = this.$get('is_del');

    let sex_config = this.admin_config('status_alias_map.user.sex');
    let forms_config = {
      score_status: {label:'积分状态',name:'where[score_status][eq]',type:'radio', config:'全部|,冻结|0,正常|1,黑名单|2',button:true,value:'',br:true},
      keyword: {label:'昵称/电话',name:'where[nickname|phone][like]',type:'text_one',value:'',br:true},
      score_level: {label:'会员等级',name:'where[score_level][eq]',type:'select_one',config:[],value:'',br:true},
    };
    let list_cols = {
      id: {name:'id', label:'ID', width:'65px', fixed:'left'},
      head_img:{name:'head_img', label:'头像', width:'45px', type:'file_img'},
      phone:{name:'phone', label:'电话号码', width:'120px'},
      nickname:{name:'nickname', label:'昵称', min_width:'120px'},
      score_level:{name:'score_level', label:'积分段位', width:'120px',type:'select_one',config:[]},

      badge_count:{name:'badge_count', label:'获得勋章', width:'80px'},
      score_count:{name:'score_count', label:'总积分', width:'80px'},
      score_exchange:{name:'score_exchange', label:'使用积分', width:'80px'},
      score_surplus:{name:'score_surplus', label:'剩余积分', width:'80px'},
      score_status:{name:'score_status', label:'积分状态', type:'radio', config:'冻结|0,正常|1,黑名单|2', width:'80px'},
    };
    if (is_del){
      list_cols['delete_time'] = {name:'delete_time', label:'注销时间', width:'165px', type:'datetime'};
    }else {
      list_cols['create_time'] = {name:'create_time', label:'注册时间', width:'165px'};
    }
    list_cols['action'] = {name:'action', label:'操作', width:'140px', type:'action', fixed:'right'};

    return {
      config: {
        api: '/admin/user/'+(is_del?'recycle':'list_score'),
        title: "会员列表"+(is_del?'(已删除)':''),
        btns: btns,
        forms_config: forms_config,
        list_cols: list_cols,
        resdata: function(list){
          return list;
        },
        limit: 20,
        p: this.$get('p', 1),
      },

      parent_list: {
        show: false,
        list_cols: {
          layer:{name:'layer', label:'层级', width:'100px', fixed:'left'},
          id: {name:'id', label:'ID', width:'65px', fixed:'left'},
          head_img:{name:'head_img', label:'头像', width:'45px', type:'file_img'},
          phone:{name:'phone', label:'电话号码', width:'120px'},
          nickname:{name:'nickname', label:'昵称', width:'120px'},
          level:{name:'level', label:'等级', width:'120px',type:'select_one',config:[]},
          money:{name:'money', label:'余额', width:'75px'},
          delete_time:{name:'delete_time', label:'注销时间', width:'165px', type:'datetime'},
        },
        list: []
      }
    }
  },
  methods: {
    to_edit(row){
      let can_edit = in_right_admin('User/info_score') && ~[0,row.tenant_id].indexOf(_config('this_tenant.id'))
      let param = {
        id: row.id,
      }
      if (!can_edit) param['is_info'] = 1;
      iframe('user/info_score?'+s94Mjs.param_encode(param))
    },
    edit_status(row, score_status){

    },
  },
  mounted() {
    let app = this;
    if (!this.__iframe) window['app'] = this;
    ajax({url:'/admin/user_score_level/list?order[id]=asc',cache:true},(res)=>{
      let level_config = [];
      res.data.list.forEach((row)=>{
        level_config.push({content:`(${row.level})${row.title}`, value:row.level});
      })
      this.config.forms_config.score_level.config = level_config;
      this.config.list_cols.score_level.config = level_config;
      return false;
    })
  }
}
</script>
